package com.imti.mapper;

import com.imti.bean.pojo.Dto;
import com.imti.bean.Nurse;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.type.JdbcType;

import java.util.List;
import java.util.Map;

public interface NuresDao {

    /*查询总条数*/
    @Select("<script> select count(*) from nurse where 1=1 " +
            "<if test=\"nurseName != null and nurseName != '' \"> and nurse_name like concat('%',#{nurseName},'%')</if>" +
            "<if test=\"state != null and state != '' \"> and state =#{state}</if></script>")
    public int NurseConut(Nurse nurse);

    /*查询列表*/
    @Select("<script>SELECT n.*,dw.desk_name desknurseName " +
            "FROM nurse n,desk_work dw " +
            "WHERE dw.desk_id = n.desk_id" +
            "<if test=\"nurse.nurseName != null and nurse.nurseName != ''\"> and nurse_name like concat('%',#{nurse.nurseName},'%')</if>" +
            "<if test=\"nurse.state != null and nurse.state != '' \"> and state =#{nurse.state}</if>" +
            " limit #{page.pageIndex},#{page.page}</script>")
    @Results(value = {
            @Result(id = true, column = "nurse_id", property = "nurseId", javaType = Integer.class, jdbcType = JdbcType.INTEGER),
            @Result(column = "desk_id", property = "deskId", javaType = Integer.class, jdbcType = JdbcType.INTEGER),
            @Result(column = "acc_id", property = "accId", javaType = Integer.class, jdbcType = JdbcType.INTEGER),
            @Result(column = "is_host", property = "isHost", javaType = String.class, jdbcType = JdbcType.VARCHAR),
            @Result(column = "nurse_name", property = "nurseName", javaType = String.class, jdbcType = JdbcType.VARCHAR),
            @Result(column = "nurse_concat", property = "nurseConcat", javaType = String.class, jdbcType = JdbcType.VARCHAR)
    })
    public List<Dto> fllNurse(Map<String,Object> map);

    /*添加护士*/
    public int insertNurse(Nurse nurse);

    /*验证手机号、邮件、紧急联系人是否存在*/
    @Select("<script> select count(*) from nurse where  " +
            "<if test=\"phone != null and phone != '' \">  phone = #{phone}</if>" +
            "<if test=\"email != null and email != '' \">  email = #{email}</if>" +
            "<if test=\"tel != null and tel != '' \">  tel =#{tel}</if></script>")
    public int selectCountOne(Nurse nurse);

    /*离职、开除、退休*/
    @Update("UPDATE nurse SET state = #{state}  WHERE nurse_id = #{nurseId}")
    public  int updateNurse(Nurse nurse);
}
